

import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_common/global_getx.dart';
import 'package:basic_common/time_tool.dart';
import 'package:basic_profile/chilidview/evaluate/evaluate_controller.dart';
import 'package:basic_profile/model/evaluate_data_list.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/button_widget.dart';
import 'package:basic_widgets/text_widget.dart';

class EvaluatePage extends GetView<EvaluateController> {
  const EvaluatePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: backAppbar(title: "我的评价"),
        body: GetBuilder<EvaluateController>(
          id: 'evaluateList',
          builder: (controller) => Container(
            padding: EdgeInsets.symmetric(horizontal: ScreenHelper.width(15)),
            child: controller.evaluateList.length == 0
                ? Align(
                    alignment: Alignment.topCenter,
                    child: EmptyBox(title: "暂无评论"))
                : ListView.builder(
                    itemBuilder: (context, index) {
                      EvaluateData evaData = controller.evaluateList[index];
                      String date = TimeTool.strToDate(evaData.appraiseTime!);
                      return itemWidget(
                          name: evaData.nickName ?? '',
                          time: date,
                          content: evaData.content ?? '',
                          replyContent: evaData.reply ?? '',
                          replyId: evaData.id!);
                    },
                    itemCount: controller.evaluateList.length,
                    shrinkWrap: true,
                  ),
          ),
        ));
  }

  /// listItem
  Widget itemWidget(
      {required String name,
      required String time,
      required String content,
      required String replyContent,
      required int replyId}) {
    return Card(
      elevation: 0,
      child: Padding(
        padding: EdgeInsets.symmetric(
            horizontal: ScreenHelper.width(5), vertical: ScreenHelper.width(5)),
        child: Column(
          children: [
            ListTile(
              title: Text("${name}",style: TextStyle(color: AppTheme.dartTextColor),),
              subtitle: Text("${time}"),
            ),
            Text("${content}"),
            replyContent.isEmpty
                ? Align(
                    alignment: Alignment.centerLeft,
                    child: ElevatedButton(
                      onPressed: () {
                        showAddReplyDialog(replyId: replyId);
                      },
                      style: ElevatedButton.styleFrom(
                          backgroundColor: AppTheme.primyColor),
                      child: Text(
                        "立即回复",
                        style: const TextStyle(color: Colors.white),
                      ),
                    ),
                  )
                : ListTile(
                    title: Text(
                      '${globalGetx.doctorInfo!.doctorNick!}回复：',
                      style: TextStyle(
                          color: AppTheme.primyColor,
                          fontSize: ScreenHelper.sp(14)),
                    ),
                    subtitle: Text(
                      replyContent,
                      style: TextStyle(
                          color: AppTheme.dartTextColor,
                          fontSize: ScreenHelper.sp(14)),
                    ),
                  ),
          ],
        ),
      ),
    );
  }

  /// 添加dialog
  void showAddReplyDialog({required int replyId}) {
    showDialog(
        context: Get.context!,
        builder: (BuildContext context) {
          return Container(
            margin: const EdgeInsets.all(10.0),
            child: SimpleDialog(
              children: [
                //这边自己定义widget内容
                Center(
                  child: Container(
                    margin: const EdgeInsets.symmetric(horizontal: 10),
                    child: TextField(
                        style: const TextStyle(
                                    color: AppTheme.dartTextColor),
                      controller: controller.replyController,
                      decoration: const InputDecoration(
                          hintText: "请输入回复内容",
                          border: OutlineInputBorder(
                              borderSide:
                                  BorderSide(color: AppTheme.primyColor)),
                          focusedBorder: OutlineInputBorder(
                              borderSide:
                                  BorderSide(color: AppTheme.primyColor)),
                          disabledBorder: OutlineInputBorder(
                              borderSide:
                                  BorderSide(color: AppTheme.primyColor)),
                          enabledBorder: OutlineInputBorder(
                              borderSide:
                                  BorderSide(color: AppTheme.primyColor))),
                    ),
                  ),
                ),
                SizedBox(
                  height: ScreenHelper.height(15),
                ),
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 10),
                  child: Row(
                    children: [
                      Expanded(
                          child: roundBtn(
                              onTap: () {
                                Get.back();
                              },
                              text: "取消",
                              bgColor: Colors.white,
                              textColor: AppTheme.primyColor,
                              borderColor: AppTheme.primyColor)),
                      SizedBox(
                        width: ScreenHelper.width(10),
                      ),
                      Expanded(
                          child: roundBtn(
                              onTap: () {
                                Get.back();
                                controller.addReply(replyId: replyId);
                              },
                              text: "回复",
                              bgColor: AppTheme.primyColor,
                              textColor: Colors.white)),
                    ],
                  ),
                )
              ],
            ),
          );
        });
  }
}
